home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing;
-
- import com.sun.java.accessibility.Accessible;
- import com.sun.java.accessibility.AccessibleContext;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.IllegalComponentStateException;
- import java.awt.LayoutManager;
-
- public class JRootPane extends JComponent implements Accessible {
- protected JMenuBar menuBar;
- protected Container contentPane;
- protected JLayeredPane layeredPane;
- protected Component glassPane;
- protected JButton defaultButton;
- protected DefaultAction defaultPressAction;
- protected DefaultAction defaultReleaseAction;
-
- public JRootPane() {
- this.setGlassPane(this.createGlassPane());
- this.setLayeredPane(this.createLayeredPane());
- this.setContentPane(this.createContentPane());
- ((Container)this).setLayout(this.createRootLayout());
- ((JComponent)this).setDoubleBuffered(true);
- ((Component)this).setBackground(UIManager.getColor("control"));
- }
-
- protected void addImpl(Component comp, Object constraints, int index) {
- super.addImpl(comp, constraints, index);
- if (this.glassPane != null && this.glassPane.getParent() == this && ((Container)this).getComponent(0) != this.glassPane) {
- ((Container)this).add(this.glassPane, 0);
- }
-
- }
-
- protected Container createContentPane() {
- JComponent c = new JPanel();
- ((Component)c).setName(((Component)this).getName() + ".contentPane");
- ((Container)c).setLayout(new 1());
- return c;
- }
-
- protected Component createGlassPane() {
- JComponent c = new JPanel();
- ((Component)c).setName(((Component)this).getName() + ".glassPane");
- c.setVisible(false);
- ((JPanel)c).setOpaque(false);
- return c;
- }
-
- protected JLayeredPane createLayeredPane() {
- JLayeredPane p = new JLayeredPane();
- ((Component)p).setName(((Component)this).getName() + ".layeredPane");
- return p;
- }
-
- protected LayoutManager createRootLayout() {
- return new RootLayout(this);
- }
-
- public AccessibleContext getAccessibleContext() {
- if (super.accessibleContext == null) {
- super.accessibleContext = new AccessibleJRootPane(this);
- }
-
- return super.accessibleContext;
- }
-
- public Container getContentPane() {
- return this.contentPane;
- }
-
- public JButton getDefaultButton() {
- return this.defaultButton;
- }
-
- public Component getGlassPane() {
- return this.glassPane;
- }
-
- public JLayeredPane getLayeredPane() {
- return this.layeredPane;
- }
-
- public JMenuBar getMenuBar() {
- return this.menuBar;
- }
-
- public boolean isValidateRoot() {
- return true;
- }
-
- public void setContentPane(Container content) {
- if (content == null) {
- throw new IllegalComponentStateException("contentPane cannot be set to null.");
- } else {
- if (this.contentPane != null && this.contentPane.getParent() == this.layeredPane) {
- this.layeredPane.remove(this.contentPane);
- }
-
- this.contentPane = content;
- this.layeredPane.add(this.contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
- }
- }
-
- public void setDefaultButton(JButton defaultButton) {
- JButton oldDefault = this.defaultButton;
- this.defaultButton = defaultButton;
- if (this.defaultPressAction == null) {
- this.defaultPressAction = new DefaultAction(this, true);
- this.defaultReleaseAction = new DefaultAction(this, false);
- ((JComponent)this).registerKeyboardAction(this.defaultPressAction, KeyStroke.getKeyStroke(10, 0, false), 2);
- ((JComponent)this).registerKeyboardAction(this.defaultReleaseAction, KeyStroke.getKeyStroke(10, 0, true), 2);
- }
-
- if (oldDefault != defaultButton) {
- this.defaultPressAction.setOwner(defaultButton);
- this.defaultReleaseAction.setOwner(defaultButton);
- if (oldDefault != null) {
- ((Component)oldDefault).repaint();
- }
-
- if (defaultButton != null) {
- ((Component)defaultButton).repaint();
- }
- }
-
- ((JComponent)this).firePropertyChange("defaultButton", oldDefault, defaultButton);
- }
-
- public void setGlassPane(Component glass) {
- if (glass == null) {
- throw new NullPointerException("glassPane cannot be set to null.");
- } else {
- boolean visible = false;
- if (this.glassPane != null && this.glassPane.getParent() == this) {
- ((Container)this).remove(this.glassPane);
- visible = this.glassPane.isVisible();
- }
-
- glass.setVisible(visible);
- this.glassPane = glass;
- ((Container)this).add(this.glassPane, 0);
- if (visible) {
- ((Component)this).repaint();
- }
-
- }
- }
-
- public void setLayeredPane(JLayeredPane layered) {
- if (layered == null) {
- throw new IllegalComponentStateException("layeredPane cannot be set to null.");
- } else {
- if (this.layeredPane != null && this.layeredPane.getParent() == this) {
- ((Container)this).remove(this.layeredPane);
- }
-
- this.layeredPane = layered;
- ((Container)this).add(this.layeredPane, -1);
- }
- }
-
- public void setMenuBar(JMenuBar menu) {
- if (this.menuBar != null && this.menuBar.getParent() == this.layeredPane) {
- this.layeredPane.remove(this.menuBar);
- }
-
- this.menuBar = menu;
- if (this.menuBar != null) {
- this.layeredPane.add(this.menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
- }
-
- }
- }
-